# https://leetcode.cn/problems/jump-game-iii/description/

from collections import deque


class Solution:
    @staticmethod
    def canReach(arr: list[int], start: int) -> bool:
        arrSize = len(arr)
        pt = deque([start])
        visited = [True if _ == start else False for _ in range(arrSize)]
        while pt:
            nowIndex = pt.popleft()
            if arr[nowIndex] == 0:
                return True
            for nextIndex in (nowIndex + arr[nowIndex], nowIndex - arr[nowIndex]):
                if 0 <= nextIndex < arrSize and not visited[nextIndex]:
                    pt.append(nextIndex)
                    visited[nextIndex] = True
        return False
